//判断是否登录
if (localStorage.user1) {
    $(".sigin").text(`你好,${localStorage.user1}`);
    $(".register").text(``);
    $(".sigin").attr("href", "");
} else {
    $(".sigin").text("你好,请登录");
    $(".register").text("注册");
}

// 购物车数量
plates = JSON.parse(localStorage.getItem("hisplate"))//取
$(".amount").text(function () {
    if (localStorage.quantity !== undefined) {
        return `(${localStorage.quantity})`
    }
})





// 搜索推荐
$(function () {
    $.ajax({
        url: "./json/comm.json", success: function (result) {
            for (let i of result.date) {
                $("#header .service .comm").append(`
                <span><a href="">${i}</a></span>
             `)
            }
        }
    });
});

// 轮播
layui.use('carousel', function () {
    let carousel = layui.carousel;
    //建造实例
    carousel.render({
        elem: '#test1'
        , width: '100%' //设置容器宽度
        , arrow: 'always' //始终显示箭头
        , height: "480px"
        , anim: "fade"
        , arrow: "hover"
    });
});


// 手机轮播
layui.use('carousel', function () {
    let carousel = layui.carousel;
    //建造实例
    carousel.render({
        elem: '#test2'
        , width: '300px' //设置容器宽度
        , arrow: 'always' //始终显示箭头
        , height: "100px"
        , anim: "fade"
        , arrow: "hover"
    });
});

//手机导航
$(function () {
    $.ajax({
        url: "./json/narrow.json", success: function (result) {
            for (let i of result.date) {
                $(".narrow-nav").append(`
                <div class="procate-item">
                     <a href="">
                        <img src="./img/narrow-home/${i.img}" alt="">
                        <div>${i.txt}</div>
                    </a>
                </div>
             `)
            }
        }
    });
});

//爱情鲜花
$(function () {
    $.ajax({
        url: "./json/love.json", success: function (result) {
            for (let i of result.data) {
                $(".lover").append(`
                <div class="pull-left commo">
                    <div><img src="./json/${i.img}" alt=""></div>
                    <p class="ellipsis">${i.name}</p> 
                    <p>￥${i.pride}</p> 
                    <p>${i.sale}<span class="fas fa-shopping-cart visible-xs-block"></span></p> 
                </div>
             `)
            }
        }
    });
});

// 长辈鲜花
$(function () {
    $.ajax({
        url: "./json/parent.json", success: function (result) {
            for (let i of result.data) {
                $(".parent-fr").append(`
                <div class="pull-left commo">
                    <div><img src="./json/${i.img}" alt=""></div>
                    <p class="ellipsis">${i.name}</p> 
                    <p>￥${i.pride}</p> 
                    <p>${i.sale}<span class="fas fa-shopping-cart visible-xs-block"></span></p> 
                </div>
             `)
            }
        }
    });
});

// 永生花
$(function () {
    $.ajax({
        url: "./json/flower.json", success: function (result) {
            for (let i of result.data) {
                $(".aa").append(`
                <div class="pull-left commo">
                    <div><img src="./json/${i.img}" alt=""></div>
                    <p class="ellipsis">${i.name}</p> 
                    <p>￥${i.pride}</p> 
                    <p>${i.sale}<span class="fas fa-shopping-cart visible-xs-block"></span></p>
                </div>
             `)
            }
        }
    });
});

// 删除鲜花专区的商品图片的文字省略
window.onresize = resizeBannerImage;
function resizeBannerImage() {
    var winW = $(window).width();
    if ($(window).width() < 768) {
        $("body .commo .ellipsis").removeClass("ellipsis")
    }
    if ($(window).width() > 768) {
        $("body .commo p").addClass("ellipsis")
    }
}

// 蛋糕品牌和分类蛋糕
$(function () {
    $.ajax({
        url: "./json/cake1.json", success: function (result) {
            for (let i of result.data) {
                $(".brand,.cake-hover").append(`
                <div>
                    <a href="">
                        <img src="./json/${i.img}" alt="">
                        <div>${i.name}</div>
                    </a>
                </div>
             `)
            }
        }
    });
});

// 蛋糕商品
$(function () {
    $.ajax({
        url: "./json/cake2.json", success: function (result) {
            for (let i of result.data) {
                $(".cakee").append(`
                <div class="pull-left commo">
                    <div><img src="./json/${i.img}" alt=""></div>
                    <p class="ellipsis">${i.name}</p> 
                    <p>￥${i.pride}</p> 
                    <p>${i.sale}<span class="fas fa-shopping-cart visible-xs-block"></span></p>
                </div>
             `)
            }
        }
    });
});


// 礼品品牌
$(function () {
    $.ajax({
        url: "./json/gift1.json", success: function (result) {
            for (let i of result.data) {
                $(".gift-brand,.gift-brand-hover").append(`
                <div class="pull-left">
                    <a href="">
                        <img src="./json/${i.img}" alt="">
                        <div>${i.name}</div>
                    </a>
                </div>
             `)
            }
        }
    });
});

// 礼品商品
$(function () {
    $.ajax({
        url: "./json/gift2.json", success: function (result) {
            for (let i of result.data) {
                $(".giftt").append(`
                <div class="pull-left commo">
                    <div><img src="./json/${i.img}" alt=""></div>
                    <p class="ellipsis">${i.name}</p> 
                    <p>￥${i.pride}</p> 
                    <p>${i.sale}<span class="fas fa-shopping-cart visible-xs-block"></span></p>
                </div>
             `)
            }
        }
    });
});

// 评论
$(function () {
    $.ajax({
        url: "./json/comment.json", success: function (result) {
            for (let i of result.data) {
                $(".comment-commo").append(`
                <div class="pull-left f-comments-item">
                   <ul class="pull-left f-comments-item-l">
                        <li><img src="./json/${i.photo}" alt=""><span>${i.name}</span></li>  
                        <li>${i.comment}</li>
                        <li>${i.area}</li>
                        <li>${i.date}</li>
                   </ul>
                   <div class="pull-right f-comments-item-r">
                        <img src="./json/${i.img}" alt="">
                   </div>
                </div>
             `)
            }
        }
    });
});

// 客户服务
$(".kffw").hover(function () {
    $(this).css({
        "background": "#fff"
    })
    $(".kffw div").css({
        "display": "block",
        "background": "#fff"
    })

}, function () {
    $(this).css({
        "background": ""
    })
    $(".kffw div").css({
        "display": "none",
        "background": "#fff"
    })
});

//返回顶部
$(function () {
    $("#toTop").click(function () {
        $("body,html").animate({
            scrollTop: 0
        }, 1000);
    })
})

// 懒加载
$("img").lazyload({
    effect: "fadeIn", // 载入使用何种效果
    // effect(特效),值有show(直接显示),fadeIn(淡入),slideDown(下拉)等,常用fadeIn
    threshold: 10, // 提前开始加载
    // threshold,值为数字,代表页面高度.如设置为200,表示滚动条在离目标位置还有200的高度时就开始加载图片,可以做到不让用户察觉
});


// 详情页的数据
$("body").on("click", ".commo", function () {
    var a = $(this).children()
    localStorage.details = [
        a.children()[0].src.split("/")[6],    //图片
        a[1].innerText,                       //标题
        a[2].innerText,                       //价格
        a[3].innerText,                       //销量
    ]
    window.location.href = "./particulars/particulars.html";
})

